package com.java.comprehensive.design.behavioral_model.Interpreter_pattern;

public class Client {
    public static void main(String[] args) {
        Context context = new Context();


        //创建多个变量对象

        Variable a = new Variable("a");
        Variable b = new Variable("b");
        Variable c = new Variable("c");
        Variable d = new Variable("d");


        context.assign(a, 1);
        context.assign(b, 2);
        context.assign(c, 3);
        context.assign(d, 4);

        //获取抽象语法树 a+b-c+d
        AbstractExpression abstractExpression = new Minus(a, new Plus(new Minus(b, c), d));
        int interpret = abstractExpression.interpret(context);

        System.out.println(abstractExpression + "=" + interpret);

    }
}
